package thinking_net;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.nio.charset.Charset;

public class ClientJava {

	public static void main(String[] args) throws Exception {
		Socket ss = new Socket("localhost", 8080);
		try {

			BufferedReader reader = new BufferedReader(
					new InputStreamReader(ss.getInputStream(), Charset.defaultCharset()));

			PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(ss.getOutputStream())),
					true);

		/*	for (int i = 0; i < 8; i++) {
				writer.println("yang " + i);
				String mes = reader.readLine();
				System.out.println("client :"+mes);
			}
			writer.println("END");*/
			
			BufferedReader system = new BufferedReader(
					new InputStreamReader(System.in, Charset.defaultCharset()));
			
			while(true){
				String input=system.readLine();
				writer.println(input);
				String mes = reader.readLine();
				System.out.println("client :"+mes);
				if(mes.equals("END")){
					break;
				}
			}
			
			system.close();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("close");
			if (ss != null)
				ss.close();
		}

	}
}
